<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>寄生组合式继承</title>
	</head>
	<body>
		寄生组合式继承
	</body>
	<script>
		// 4、寄生组合式继承
		function inheritPrototype(subType, superType) {
			var myprototype = Object(superType.prototype); //创建对象
			myprototype.constructor = subType; //增强对象
			subType.prototype = myprototype; //指定对象
		}

		function SuperType(name) {
			this.name = name;
			this.colors = ["red", "blue", "green"];
		}
		SuperType.prototype.sayName = function() {
			console.log(this.name);
		};

		function SubType(name, age) {
			SuperType.call(this, name);
			this.age = age;
		}
		inheritPrototype(SubType, SuperType);
		SubType.prototype.sayAge = function() {
			console.log(this.age);
		};

		let sub1 = new SubType('诸葛亮', 36)
		console.log(sub1);

	</script>
</html>
